    ' Copyright 2009, 2010 Massimo Franciosa
    'This file is part of MYLK.

    'MYLK is free software; you can redistribute it and/or modify
    'it under the terms of the GNU General Public License as published by
    'the Free Software Foundation; either version 2 of the License, or
    '(at your option) any later version.

    'Nome-Programma is distributed in the hope that it will be useful,
    'but WITHOUT ANY WARRANTY; without even the implied warranty of
    'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    'GNU General Public License for more details.

    'You should have received a copy of the GNU General Public License
    'along with Nome-Programma; if not, write to the Free Software
    'Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

Imports System.Windows.Forms

Public Class CustomCombo

  Inherits ComboBox

  Private lstImg As New ImageList
      'It is the ImageList associated to the Combo
  Public Property ImageList() As ImageList
    Get
      Return lstImg
    End Get
    Set(ByVal value As ImageList)
      lstImg = value
    End Set
  End Property

  Public Sub New()
      DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed

  End Sub

  Protected Overrides Sub OnDrawItem(ByVal e _
          As System.Windows.Forms.DrawItemEventArgs)
      e.DrawBackground()
      e.DrawFocusRectangle()
      Dim item As New ComboBoxIconItem
      Dim imageSize As New Size
      imageSize = lstImg.ImageSize
      Dim bounds As New Rectangle
      bounds = e.Bounds
      Try
          item = Me.Items(e.Index)
          If (item.ImageIndex <> -1) Then
              Me.ImageList.Draw(e.Graphics, bounds.Left, _
                  bounds.Top, item.ImageIndex)
              e.Graphics.DrawString(item.Text, e.Font, _
                  New SolidBrush(e.ForeColor), bounds.Left + _
                  imageSize.Width, bounds.Top)
          Else
              e.Graphics.DrawString(item.Text, e.Font, _
                  New SolidBrush(e.ForeColor), bounds.Left, _
                  bounds.Top)
          End If
          Catch ex As Exception
          If (e.Index <> -1) Then
              e.Graphics.DrawString(Items(e.Index).ToString(), e.Font, _
                  New SolidBrush(e.ForeColor), bounds.Left, bounds.Top)
          Else
              e.Graphics.DrawString(Text, e.Font, _
                  New SolidBrush(e.ForeColor), bounds.Left, bounds.Top)
          End If
      End Try
    MyBase.OnDrawItem(e)

  End Sub


End Class

Public Class ComboBoxIconItem
    Private sText As String
    Public Property Text() As String
      Get
        Return sText
      End Get
      Set(ByVal value As String)
        sText = value
      End Set
    End Property

    Private oValue As Object
    Public Property Value() As Object
      Get
        Return oValue
      End Get
      Set(ByVal value As Object)
        oValue = value
      End Set
    End Property

    Private nImageIndex As Integer
    Public Property ImageIndex() As Integer
      Get
        Return nImageIndex
      End Get
      Set(ByVal value As Integer)
        nImageIndex = value
      End Set
    End Property

    Public Sub New()
      Me.New("", -1, Nothing)
    End Sub

    Public Sub New(ByVal sText_p As String)
      Me.New(sText_p, -1, Nothing)
    End Sub

    Public Sub New(ByVal sText_p As String, ByVal nImageIndex_p As Integer, ByVal oValue_p As Object)
      sText = sText_p
      nImageIndex = nImageIndex_p
      oValue = oValue_p
    End Sub

End Class





